

unit UFlash;


interface

uses
  Windows, SysUtils, Classes,
  Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, Buttons,
  uIFlashInterface, ExtCtrls, jpeg;


type

  TfrmFlash = class(TForm, {IUnknown, }IFlashInterface)
    LabelProcessing: TLabel;
    ProgressBar: TProgressBar;
    imgFlash: TImage;
  private
    //number of references on the interface
    FRefCount: Integer;
    { private declarations }
  public
    //Frees the window.
    destructor Destroy; override;

    //Increments the reference count of the interface.
    function DoAddRef: Integer; stdcall;
    //Decrements the reference count of the interface.
    function DoRelease: Integer; stdcall;

    function IFlashInterface._AddRef = DoAddRef;
    function {UProgress.}IFlashInterface._Release = DoRelease;
    procedure Prepare; virtual;
    function SetProcessText(const Text: String): Boolean;
    procedure SetMaximum(NewMax: Integer);
    procedure Reset;
    function StepProgress: Boolean;
    procedure Finished;
    { public declarations }
  end;


implementation

{$R *.dfm}

destructor TfrmFlash.Destroy;
begin
 inherited Destroy;                 //free the window
end;

function TfrmFlash.DoAddRef: Integer;
begin
 Result := InterlockedIncrement(FRefCount);  //increment the counter
end;

function TfrmFlash.DoRelease: Integer;
begin
 Result := InterlockedDecrement(FRefCount);  //decrement the counter
 if Result = 0 then                          //reached 0?
  Destroy;                                     //free the not-referenced object
end;


{Prepares the window for a completely new action to show the progress of. }
procedure TfrmFlash.Prepare;
begin
 ModalResult := mrNone;                    //don't close immediately again
 Show;                                     //show the form

end;


function TfrmFlash.SetProcessText(const Text: String): Boolean;
begin
  LabelProcessing.Caption := Text;   //show the text
  LabelProcessing.Update;
end;


procedure TfrmFlash.SetMaximum(NewMax: Integer);
begin
 ProgressBar.Position := 0;
 ProgressBar.Max := NewMax;         //set maximum position of progress
end;


procedure TfrmFlash.Reset;
begin
 ProgressBar.Position := 0;
end;


function TfrmFlash.StepProgress: Boolean;
var      WasLessAMinute   :Boolean;      //if the time was less than a minute
begin
 ProgressBar.StepIt;                     //step the progress
 Application.ProcessMessages;            //handle messages (Abort/Pause/beep)?
end;


procedure TfrmFlash.Finished;
begin
  if Visible then                           //not already finished?
  begin
    Hide;                                     //close the window
  end;
end;





end.

   